package wc;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class PrintToFile {
	String outputFileName = null;// 默认输入到result中

	PrintToFile() {

	}

	PrintToFile(String outputFileName) {
		this.outputFileName = outputFileName;
	}

	public void outputToFile(String result) throws IOException {//将结果输出到文件中
		
		
		String filePath = null;
		File file = new File("..");
		filePath = file.getAbsolutePath()+"/"+outputFileName;
		File outputFile = new File(filePath);
		if(outputFile.exists()==false) {
			outputFile.createNewFile();
		}
        FileWriter fw = new FileWriter(filePath,true);//以追加的方式写入文件
		fw.write(result+"\n");
		fw.close();
	}


}
